package cn.mogugo;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class SetEncodeFilter  implements Filter { 
	private String encodingStr;

	
	private String redirectURL = null;

	/**
	* 无参构造方法.
	*
	*/
	public SetEncodeFilter() {}
	/**
	* 过滤器初始化方法.
	* 
	* @param fc 读取配置文件参数.
	*/
	public void init(FilterConfig fc) throws ServletException {
	   encodingStr = fc.getInitParameter("defaultencoding");
	   redirectURL = fc.getInitParameter("redirectURL");
	}

	/**
	* servlet的doFilter()方法.
	* 关键字过滤检查
	* 1、与KeyWord_NoBlank字典进行不带空格的关键字比较
	* 2、将参数按照空格分割，与KeyWord_Blank字典进行比较
	*/
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		
		HttpServletRequest httpRequest = (HttpServletRequest)request;
		HttpServletResponse httpResponse = (HttpServletResponse) response;
		httpResponse.setCharacterEncoding(encodingStr);
		httpRequest.setCharacterEncoding(encodingStr);
		
		chain.doFilter(request, response);
		return;
		
	}

	/**
	* 过滤器销毁方法.
	*/
	public void destroy() {
		
	}

}
